package com.w1.security.controller;


import com.w1.security.domain.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author mingyifan
 * @date 2022-02-16 08:50
 */
@RestController
@RequestMapping("/user")
public class LoginController {


    @RequestMapping("/l")
    public ResponseResult login(){
        return new ResponseResult(200,"登陆成功");
    }
    @RequestMapping("/logout")
    public ResponseResult logout(HttpServletRequest request, HttpServletResponse response){
        Cookie cookie_username = new Cookie("Authorization", null);
        // 设置cookie的持久化时间，0
        cookie_username.setMaxAge(0);
        // 设置为当前项目下都携带这个cookie
        cookie_username.setPath("/");
        // 向客户端发送cookie
        response.addCookie(cookie_username);
        return new ResponseResult(200,"成功",cookie_username);
    }
}